<?php
	defined('_JEXEC') or die('Restricted access'); 
	$task = isset($_GET['action'])&&$_GET['action']=='edit'?'edit':'new';
	$url = $this->baseurl.'/images/com_retailshop/';
	$task = $_GET['task'];	
?>
<div class="wrapper wmain">
<div id="content">
    <div id="nav">
		<h2>Add New Category</h2>
        <ul>
			<li><a href="#product-add-general">Category general</a></li>
        </ul>
	</div>	
	<div id="manager">
		
		<form id="adminForm" name="adminForm" action="index.php?option=com_retailshop" method="post" enctype="multipart/form-data">
		<div id="toolbar-box">
              <div class="toolbar">
                <ul>
					<li class="toolbar-save" id="savecate"><a href="#"><span class="icon-save"></span>Save</a></li>
					<li class="toolbar_cancel"><a href="index.php?option=com_retailshop&view=myshop&task=setting"><span class="icon-cancel"></span>Cancel</a></li>
                </ul>
              </div>
              <div class="title">
                <h2>Category Manager: Add New Category</h2>
              </div>
            </div>  
		<div id="product-add-general"> 
			<div class="element">				
				<span id="err-catelogy">					
				</span>
			</div>
			<div class="element">
				<label>Category Parent</label>
				<select name="start-catagory">
					<option value="-1">-- None --</option>
					<?php for($i = 0; $i<count($this->menu); $i++) { ?>
						<option value="<?php echo $this->menu[$i]->id; ?>"><?php echo $this->menu[$i]->name; ?></option>
					<?php } ?>
				</select>
			</div>
			<div class="element">
				<label>Menu</label> 
				<input type="checkbox" name="menu" value="1" <?php if($task =='editcatelogy') echo $this->cate->is_menu == 1 ?' checked ':''; ?>/>
			</div>
			<div class="element">
				<label>Category Name</label>
				<input type="text" name="cat-name" value="<?php echo $task =='editcatelogy'? $this->cate->name : ''; ?>" />
			</div>			
		</div>          
			<input type="hidden" name="view" value="myshop" />
			<input type="hidden" name="task" value="savecate" />
			<input type="hidden" name="action" value="<?php echo $task=='editcatelogy' ? 'edit' : 'addnew'?>" />
			<?php echo $task=='editcatelogy' ? '<input type="hidden" name="id" value="'.$this->cate->id.'" />' : ''?>
		</form>
	</div>
</div>	
</div>

<script>
	$('#savecate').click(function() {
		var cat_name = $('input:text[name="cat-name"]').val();		
		var err = '';
		if(cat_name=='')
			err +='<p>Please enter name catelogy</p>';
		if(err.length != 0){		
			$('#err-catelogy').html(err);
			return false;
		}else{
			$('#err-catelogy').addClass('validate-form');
			$('#err-catelogy').html('');
		}		
		$('#adminForm').submit();
	});
</script>